import 'package:dance_todo/db/bean_event.dart';
import 'package:dance_todo/pages/BarChartSample1.dart';
import 'package:dance_todo/pages/controller_schedule.dart';
import 'package:dance_todo/pages/controller_statistic.dart';
import 'package:dance_todo/res/res_colors.dart';
import 'package:dance_todo/utils/formatter_input.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class StatisticPage extends StatefulWidget {
  const StatisticPage({Key? key}) : super(key: key);

  @override
  State<StatisticPage> createState() => _StatisticPageState();
}

class _StatisticPageState extends State<StatisticPage> {
  final TextEditingController _nameInputCtrl = TextEditingController();
  final TextEditingController _countInputCtrl = TextEditingController();

  @override
  void initState() {
    super.initState();
    StatisticCtrl.to.analysisStatisticBeans();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.black87,
      child: SafeArea(
        child: Container(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  child: const Text(
                    '打卡统计',
                    style: TextStyle(
                      color: ColorTitle,
                      fontSize: 70.0,
                    ),
                  ),
                ),
                Expanded(child: buildStatisticContainer()),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget buildStatisticContainer() {
    return Obx(() {
      var width = MediaQuery.of(context).size.width*4/5;
      var statistics = StatisticCtrl.to.statistics.value;
      print('width= $width');
      return ListView.builder(
        itemBuilder: (context, index) {
          int count = statistics[index].count;
          int maxCount = statistics[index].maxCount;
          print('widthItem= ${width * count * 1.0 / maxCount}');
          return Row(
            children: [
              Container(
                child: Text(
                  statistics[index].name,
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.blue,
                  ),
                  height: 20.0,
                  width: width * count * 1.0 / maxCount,
                ),
              ),
            ],
          );
        },
        itemCount: statistics.length,
      );
    });
  }
}
